﻿
using BaseUtils.Helper;
using BaseUtils.Logger;
using NWMES.Mes;
using NWMES.Model;
using Service.src.Flow.Server;
using Service.src.Model.Folw;
using Service.src.NW.Model;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace Service.src.Api
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class FlowApi
    {

        /// <summary>
        /// 添加流程节点
        /// </summary>
        /// <param name="FolwId"></param>
        /// <param name="TypeId"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        /// <param name="MaxX"></param>
        /// <param name="MaxY"></param>
        /// <param name="GroupId"></param>
        /// <returns></returns>
        //public string AddFlowNode(long FlowId, int TypeId, int X, int Y, int MaxX, int MaxY, string GroupId)
        //{
        //    FlowServer flowServer = new FlowServer();
        //    return flowServer.AddFlowNode(FlowId, TypeId, X, Y);
        //}

        /// <summary>
        /// 更新节点
        /// </summary>
        /// <param name="NodeItemJson"></param>
        /// <param name="GroupJson"></param>
        /// <returns></returns>
        //public string UpdateFlowNode(long FlowId, string NodeItemJson, string GroupJson)
        //{
        //    FlowServer flowServer = new FlowServer();
        //    return flowServer.UpdateFlowNode(FlowId, NodeItemJson);
        //}

        /// <summary>
        /// 更新节点的运行参数
        /// </summary>
        /// <param name="FolwId"></param>
        /// <param name="NodeItemDataJson"></param>
        /// <param name="GroupJson"></param>
        /// <returns></returns>
        //public string UpdateFlowNodeParams(
        //    long FlowId, int NodeId, string NodeItemParamsJson, string NodeName, int NodeTimeOut, bool IsPreCompiling = false)
        //{
        //    FlowServer flowServer = new FlowServer();
        //    return flowServer.UpdateFlowNodeParams(FlowId, NodeId, NodeItemParamsJson, NodeName, NodeTimeOut, IsPreCompiling);
        //}

        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="FolwId"></param>
        /// <param name="NodeItemJson"></param>
        /// <param name="GroupJson"></param>
        /// <returns></returns>
        //public string DeleteFlowNode(long FlowId, string NodeIds, string LinkIds, string GroupJson)
        //{
        //    FlowServer flowServer = new FlowServer();
        //    return flowServer.DeleteFlowNode(FlowId, NodeIds, LinkIds);
        //}

        /// <summary>
        /// 创建节点连线
        /// </summary>
        /// <param name="FolwId"></param>
        /// <param name="SourceNodeId"></param>
        /// <param name="TargetNodeId"></param>
        /// <param name="SourcePort"></param>
        /// <returns></returns>
        //public string CreateConnection(long FlowId, int SourceNodeId, int TargetNodeId, int SourcePort)
        //{
        //    FlowServer flowServer = new FlowServer();
        //    return flowServer.CreateConnection(FlowId, SourceNodeId, TargetNodeId, SourcePort);
        //}

        /// <summary>
        /// 克隆节点
        /// </summary>
        /// <param name="FolwId"></param>
        /// <param name="NodeIds"></param>
        /// <param name="ConnectionJson"></param>
        /// <returns></returns>
        public string CloneNode(long SourceFlowId, long FlowId, string NodeIds, string ConnectionJson)
        {
            FlowServer flowServer = new FlowServer();
            return flowServer.CloneNode(SourceFlowId, FlowId, NodeIds, ConvertHelper.ToObject<List<Connection>>(ConnectionJson));
        }

        /// <summary>
        /// 更新mes的请求参数
        /// </summary>
        /// <param name="ApiName"></param>
        /// <param name="RequestJson"></param>
        /// <returns></returns>
        //public string SaveMesNodeRequestParams(string ApiName, string RequestJson)
        //{
        //    MesBaseEntity mesBaseEntity = ConvertHelper.ToObject<MesBaseEntity>(RequestJson);
        //    new MESBaseService().UpdateMesRequestParams(ApiName, mesBaseEntity);
        //    return null;
        //}

        /// <summary>
        /// 修改节点的参数值
        /// </summary>
        /// <param name="NodeId"></param>
        /// <param name="Param"></param>
        /// <param name="Value"></param>
        /// <returns></returns>
        public bool UpdateFlowNodeParam(long FlowId, int NodeId, string Param, int Value)
        {
            FlowServer flowServer = new FlowServer();
            flowServer.UpdateFlowNodeParam(FlowId, NodeId, Param, Value);
            return true;
        }

        //public string GetMesNodeRequestParams(string ApiName)
        //{
        //    string Config = null;
        //    try
        //    {
        //        Config = MesBaseEntity.config[ApiName].ToObject<MesBaseEntity>().ToJson();
        //    }
        //    catch (System.Exception ex)
        //    {
        //        LoggerService.Error("请检查MES配置文件是否存在", ex);
        //    }
        //    return Config;
        //}

        /// <summary>
        /// 获取所有节点的详细信息
        /// </summary>
        /// <returns></returns>
        //public string GetAllFlowNodeDetail()
        //{
        //    return AppData.OpenFlows.Values.ToJson();
        //}
    }
}
